/*
 * Copyright 2007 Mojo Chen
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

var linkxdFoo = {
	
	  toTest:function(){
	  	this.getSelectHtmlStr();
	  },
	
	    getSelectHtmlStr: function(){
    	// search viewPartialSource.js for firefox's view partial source funcion.
    	// http://dylanschiemann.com/articles/dom2Range/dom2RangeExamples.html
		var fwin = document.commandDispatcher.focusedWindow;
		var sel = fwin.getSelection();
		//alert("sel anchorOffset : " + sel.anchorOffset);
		//alert("sel focusOffset : " + sel.focusOffset);
		//alert("sel rangeCount : " + sel.rangeCount);
		var range = sel.getRangeAt(0);
		var startContainer = range.startContainer;
  		var endContainer = range.endContainer;
  		var startOffset = range.startOffset;
  		var endOffset = range.endOffset;
		//alert('range StartContainer:' + startContainer);
		//alert('range EndContainer:' + endContainer);
		//alert('range startOffset:' + startOffset);
		//alert('range endOffset:' + endOffset);
		
		
		//Returns a document fragment copying the nodes of a Range.
		//var documentFragment = range.cloneContents().wrappedJSObject;
		var documentFragment = range.cloneContents();
		//http://developer.mozilla.org/en/docs/XPCNativeWrapper
		//var startContainer = range.startContainer;
		//var startContainer = range.startContainer.wrappedJSObject;
		
		// http://developer.mozilla.org/en/docs/DOM:document.createDocumentFragment
		//alert('documentFragment:' + documentFragment);
		//alert('documentFragment nodeValue:' + documentFragment.nodeValue);
		//alert('documentFragment textContent:' + documentFragment.textContent);
			//var newDiv = document.createElement("div");
			//newDiv.innerHTML = "<p>Hi</p>";
			//newDiv.appendChild(documentFragment);
			//alert('newDiv innerHTML:' + newDiv.innerHTML);
			// Returns the deepest Node that contains the startContainer and endContainer Nodes.
		var rangeAncestor = range.commonAncestorContainer;
		rangeAncestor.style.border = "solid red 2px";
		rangeAncestor.style.color = "#C0C0C0";
		alert('rangeAncestor innerHTML:' + rangeAncestor.innerHTML);
		var links = rangeAncestor.getElementsByTagName("a");
		var num = links.length;
		alert('Links num : ' + num);
		var str = "links:";
		for(i=0 ; i < num ; i++){
			str+=links[i].getAttribute("href");
			str+='\r\n';
		};
		alert(str);
    	return 'done';
  	},
  	
  	testImgSelect: function(){
    	try{
    		//alert(gContextMenu);
    		// gContextMenu.target = HTMLImageElement
    		// gContextMenu.onImage = true;
    		// gContextMenu.onLink = true;
    		// gContextMenu.hasBGImage = true;
    		var linkURL = gContextMenu.linkURL;
			//var linkText = gContextMenu.linkText();
			var target = gContextMenu.target;
			var parent1 = target.parentNode.parentNode;
			parent1.style.border = "solid red 2px";
			parent1.style.color = "#C0C0C0";
			//alert(parent1.tagName);
    	}catch(err){
    		alert(err);
    	}  		
    	// Just Test
	  	// background-color: #FFFFFF;
	  	
	  	//content.document.getElementsByTagName("div")[0].style.border = "solid red 2px";
	  	//content.document.getElementsByTagName("div")[0].style.backgroundColor = "#AAAAAA";
	  	//node.style.border = "solid red 2px";
  	},
}
